﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using System.Collections;

using Global;

namespace Pacman_3D
{
  class IngameMenu
  {
    public enum Status
    {
      gameContinue = 1,
      gameBackToMenu,
      gameExit,

      FirstMenuPos = gameContinue,
      LastMenuPos = gameExit


    };


    public IngameMenu()
    {
        pozycja = new Vector2(150, 20);
        Stan = Status.gameContinue;

        killSwitch = false;
            
    }

    public Vector2 pozycja { get; set; }

    public bool killSwitch;
    public bool mainMenuReturn = false;

    private Status m_stan;
    public Status Stan
    {
        get
        {
            return m_stan;
        }
        set
        {
            m_stan = value;
        }
    }

    public bool Update(GameTime gametime)
    {
        if( KeyboardExt.keyPressedOnce( Keys.Up ) )
          if( Stan > Status.FirstMenuPos )
          {
            Stan--;
          }
          else
            Stan = Status.LastMenuPos;

        if( KeyboardExt.keyPressedOnce( Keys.Down ) )
          if( Stan < Status.LastMenuPos )
          {
            Stan++;
          }
          else
            Stan = Status.FirstMenuPos;


        if( KeyboardExt.keyPressedOnce( Keys.Enter ) )
        {
          if( Stan == Status.gameContinue )
            return true;


          if( Stan == Status.gameBackToMenu )
          {
            mainMenuReturn = true;
            return false;
          }
              
          if( Stan == Status.gameExit )
          {
            killSwitch = true;
            return false;
          }

        }

        

        return false;
    }
  }

    class Menu
    {
      public enum Status
      {
        menuStart = 1,
        menuControls,
        menuAbout,
        menuScores,
        menuExit,
        

        FirstMenuPos = menuStart,
        LastMenuPos = menuExit


      };
      public enum Background
      {
        Default = 0,
        About = 1,
        Scores,
        Controls


      }
        private Status m_stan;
        private Background bg_tex;
        public Background BGTex
        {
          get
          {
            return bg_tex;
          }
          set
          {
             bg_tex = value;
          }

        }

        public Texture2D menuAbout { get; set; }
        public Texture2D menuStart { get; set; }
        public Texture2D menuControls { get; set; }
        public Texture2D menuScores { get; set; }
        public Texture2D menuExit { get; set; }
        public Texture2D About { get; set; } 
        public Texture2D Scores { get; set; }
        public Texture2D Controls { get; set; }
        public Vector2 pozycja { get; set; }

        public Menu(ContentManager content)
        {
            menuAbout = content.Load<Texture2D>("Menu\\pacmanAbout");
            menuStart = content.Load<Texture2D>("Menu\\pacmanStart");
            menuControls = content.Load<Texture2D>("Menu\\pacmanControl");
            menuScores = content.Load<Texture2D>("Menu\\pacmanScores");
            About = content.Load<Texture2D>("Menu\\About");
            Scores = content.Load<Texture2D>("Menu\\scores");
            menuExit = content.Load<Texture2D>( "Menu\\pacmanExit" );
            Controls = content.Load<Texture2D>( "Menu\\controls" );
            pozycja = new Vector2(150, 20);
            Stan = Status.menuStart;
            BGTex = Background.Default;
            menuCounterFreeze = false;
            killSwitch = false;
            
        }

        public bool killSwitch;

        public bool menuCounterFreeze;
        public Status Stan
        {
            get
            {
                return m_stan;
            }
            set
            {
              if( !menuCounterFreeze )
                m_stan = value;
            }
        }

        public bool Update(GameTime gametime)
        {
            if( KeyboardExt.keyPressedOnce( Keys.Up ) )
              if( Stan > Status.FirstMenuPos )
              {
                Stan--;
              }
              else
                Stan = Status.LastMenuPos;

            if( KeyboardExt.keyPressedOnce( Keys.Down ) )
              if( Stan < Status.LastMenuPos )
              {
                Stan++;
              }
              else
                Stan = Status.FirstMenuPos;

            if( KeyboardExt.keyPressedOnce( Keys.Enter ) )
            {
              if( Stan == Status.menuStart )
                return true;

              if( menuCounterFreeze == true )
              {
                menuCounterFreeze = false;
                BGTex = Background.Default;
                return false;
              }

              if( Stan == Status.menuAbout )
              {
                BGTex = Background.About;
                menuCounterFreeze = true;
                return false;
              }
              if( Stan == Status.menuScores )
              {
                BGTex = Background.Scores;
                menuCounterFreeze = true;
                return false;
              }
              //autorowi chodziło raczej o coś w tym stylu...
              if( Stan == Status.menuControls )
              {
                menuCounterFreeze = true;
                BGTex = Background.Controls;
                return false;
              }

              if( Stan == Status.menuExit )
              {
                killSwitch = true;

              }
            }
          /*
            if( KeyboardExt.keyPressedOnce( Keys.Escape ) )
            {
              BGTex = Background.Default;
              menuCounterFreeze = false;
              return false;

            }
          */
            return false;
        }

        public Texture2D GetScreen()
        {
          switch( BGTex )
          {
            case Background.About:
              return About;
            case Background.Scores:
              return Scores;
            case Background.Controls:
              return Controls;

          }

          switch (Stan)
          {
              case Status.menuStart:
                  return menuStart;
              case Status.menuControls:
                  return menuControls;
              case Status.menuAbout:
                  return menuAbout;
              case Status.menuScores:
                  return menuScores;
              case Status.menuExit:
                  return menuExit;
              default:
                  return null;
             
              
          }


        }


    }
}

